//
//  MessageViewController.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/10/14.
//  Copyright © 2017年 bob. All rights reserved.
//

#import "MessageViewController.h"
#import "SendMsgViewController.h"
#import "SendListViewController.h"
#import "ReceiveMsgViewController.h"
#import "MsgReqModel.h"
#import "ListMsgNumTableViewCell.h"
@interface MessageViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)TB_TableView *homeTableView;

@end

@implementation MessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    self.title=@"消息";
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:kColorRGBA(0x2E4361, 1)] forBarMetrics:UIBarMetricsDefault];
    
    [self.view addSubview:self.homeTableView];
    
    // Do any additional setup after loading the view.
}


-(TB_TableView*)homeTableView
{
    if (!_homeTableView) {
     
        _homeTableView=[[TB_TableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
        
        _homeTableView.delegate=self;
        
        _homeTableView.dataSource=self;
        
//        [_homeTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        
        [_homeTableView registerNib:[UINib nibWithNibName:@"ListMsgNumTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
        
        _homeTableView.tableFooterView=[[UIView alloc]init];
        
    }
    return _homeTableView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 3;
    
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ListMsgNumTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

   
    
    if (indexPath.row==0) {
        
        cell.NameLabel.text=@"收件箱";
        
         cell.NumLabel.text=self.NoreadNum;
        
    }else if (indexPath.row==1)
    {
        cell.NameLabel.text=@"发件箱";
        
         cell.NumLabel.text=@"";
        
    }else{
        
        cell.NameLabel.text=@"写消息";
        
          cell.NumLabel.text=@"";
    }
    
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 50*SCREEN_WIDTH/320.0;
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        
        MsgReqModel *list=[MsgReqModel new];
        
         list.loginType=[LoginStatuesModel getUserType];
        
        ReceiveMsgViewController *receive=[ReceiveMsgViewController new];
        
        receive.isEdit=NO;
        
        receive.isdeleMore=YES;
        
        receive.ishidenSearch=YES;
        
        if ([self getUserType]==1) {
  
            list.receiverId=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shopId]];
            
        }else{
   
            list.receiverId=[NSString stringWithFormat:@"%ld",[LoginStatuesModel getStaffId]];
            
        }
        
        receive.Reqmodel=list;
        
        receive.title=@"收件箱";
        
        [self.navigationController pushViewController:receive animated:YES];
 
    }else if (indexPath.row==1)
    {
        
        MsgReqModel *list=[MsgReqModel new];
        
        list.loginType=[LoginStatuesModel getUserType];
  
        SendListViewController *SendList=[SendListViewController new];
 
        SendList.isEdit=NO;
        
        SendList.isdeleMore=YES;
        
        SendList.ishidenSearch=YES;
        
        if ([self getUserType]==1) {
            
            list.senderId=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shopId]];
            
        }else{
            
            list.senderId=[NSString stringWithFormat:@"%ld",[LoginStatuesModel getStaffId]];
            
        }
        
        SendList.Reqmodel=list;
        
        SendList.title=@"发件箱";
        
        [self.navigationController pushViewController:SendList animated:YES];
        
       
    }else{
        
        SendMsgViewController *send=[SendMsgViewController new];
        
        [self.navigationController pushViewController:send animated:YES];

        
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
